package com.tuling.proxy;

import org.aopalliance.intercept.MethodInterceptor;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JDKproxy {
    public static void main(String[] args) {
        UserServiceInterface userServiceInterface = new UserServiceImpl();
        UserServiceInterface obj =(UserServiceInterface) Proxy.newProxyInstance(UserServiceImpl.class.getClassLoader(), new Class[]{UserServiceInterface.class}, new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("before");
                Object result = method.invoke(userServiceInterface, args);
                System.out.println("after");
                System.out.println("yyyyyyyy");
                return result;
            }
        });

        String test = obj.test();
        System.out.println(test);
    }
}
